<template>
  <div class="gk-layout-container">
    <!--工具栏-->
    <div class="gk-layout-header">
  	<s-query perms="report:ios"   @click="findPage" >
  
         	<s-date  :p="filters.begin" @dateChange="function(v){filters.begin=v}" placeholder="开始时间" />
			      <s-date  :p="filters.end"  @dateChange="function(v){filters.end=v}" placeholder="结束时间" />
            	<s-item v-model="filters.itemId"></s-item>
    </s-query>
         <s-reflash excel="true" @exportExcel="exportExcel"> 
            <el-tooltip content="同步收发存" placement="top">
              <el-button  label="生成"  @click="statIso" >生成</el-button>
            </el-tooltip>
         </s-reflash>
    </div>
    <div class="gk-layout-main">
        <my-table :data="pageResult" :loading="loading"  >
            <el-table-column :label="$t('action.desc')" width="50" header-align="center" align="center">
              <template slot-scope="scope"> {{scope.$index+1}} </template>
            </el-table-column>
            <column prop="itemId" label="物料名称"     width="400"    :formatter="itemFilter"/>
            <column prop="termIn" label="入库"   />  
            <column prop="termOut" label="出库"     />  
            <column prop="termEnd" label="库存"    />
            <column prop="id" label="单位"   :formatter="selectionFormat1"/>  
            <column prop="createTime" label="日期"   :formatter="dateFormat"/>  
          </my-table>
      </div> 
 
   
  </div>
</template>

<script>
   import {getItemName,dictsFormat,getItem} from "@/utils/myUtil"
   import {format2,formatWithDay} from "@/utils/datetime"
   import SReflash from "@/components/Kj/SReflash"
import KtButton from "@/views/Core/KtButton";  
import MyTable from "@/views/Core/MyTable"
import Column from "@/views/Core/Column"
import SDict from "@/components/Kj/SDict"
import SDictForm from "@/components/Kj/SDictForm"
import SQuery from "@/components/Kj/SQuery" 
    import SDate from "@/components/Kj/SDate"
    import SItem from "@/components/Kj/SItem"
export default {
  components: {
        Column,
        KtButton,
        MyTable,
        SDict,
        SDictForm,
        SQuery,SReflash,
        SDate,SItem
      },
  data() {
    return {
      size: "small", 
      filters: { 
        begin:format2(new Date(new Date().getTime()-3*86400000 )),
        end:format2(new Date()),
        itemId:0
      },
      loading:false, 
      pageResult: [],   
    };
  },
  methods: {
    // 获取分页数据
    findPage: function(data) { 
			 var d ={b:this.filters.begin,e:this.filters.end,itemId:this.filters.itemId} 

       this.$api.report.iosList(d) .then(res => {
          this.pageResult = res.data; 
        })
         
    }, 

    statIso: function(data) {  
       this.$api.report.statIos() .then(res => {
         this.findPage(-1)
        })
         
    }, 
    	itemFilter: function (row, column, cellValue, index) {
		 			var item=getItemName(cellValue)
					return item;
			},
  //导出的方法
    exportExcel(xlsExport) {
  	 var d ={b:this.filters.begin,e:this.filters.end,itemId:this.filters.itemId}  
       this.$api.report.iosList(d) .then((res) => {
        const tHeader = ['编号', '物料名称', '规格', '入库', '出库','当前','单位',"日期"];
        const filterVal = [ 'code', 'name', 'gg', 'termIn','termOut','termEnd', 'unit',"createTime"];
     
        for (var j = 0; j <  res.data.length; j++) {
          var d=res.data[j];
          var item= getItem(d.itemId)
            d.name=item.n;
            d.code=item.c;
            d.gg=item.g;
            d.unit=dictsFormat( "units",item.u)
            d.createTime=formatWithDay( d.createTime,'-')
        }
        xlsExport(tHeader, filterVal, res.data, '收发存');
      })
    },
 	  selectionFormat1: function (row, column, cellValue, index) {
					var i=getItem(row.itemId)

				  return dictsFormat( "units",i.u)
    },
    dateFormat: function (row, column, cellValue, index) { 
      debugger
				  return formatWithDay( cellValue,'-')
    },
  },
  mounted() {  
    this.findPage()
  }
};
</script>

<style scoped>
</style>